package pl.com.kyhu.dietex3000.database.beans;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "INGREDIENT")
public class Ingredient {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "INGREDIENT_ID")
	private Integer id;

	@Column(name = "NAME")
	private String name;

	@ManyToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "CATEGORY_ID")
	private IngredientCategory category;

	@OneToOne(cascade = { CascadeType.ALL })
	@JoinColumn(name = "NUTRIENTS_ID")
	private Nutrients nutrients;

	public Ingredient() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Nutrients getNutrients() {
		return nutrients;
	}

	public void setNutrients(Nutrients nutrients) {
		this.nutrients = nutrients;
	}

	public String getCategory() {
		return category.getName();
	}

	public void setCategory(IngredientCategory category) {
		this.category = category;
	}

	@Override
	public String toString() {
		return name;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		Ingredient other = (Ingredient) obj;
		if (name == null) {
			if (other.name != null) return false;
		} else if (!name.equals(other.name)) return false;
		return true;
	}

}
